package com.yixun.lbx.service.impl;

import com.yixun.lbx.entity.YxProBreedFeed;
import com.yixun.lbx.mapper.farm.BreedFeedMapper;
import com.yixun.lbx.service.BreedFeedService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class BreedFeedServiceImpl implements BreedFeedService {
    private final BreedFeedMapper breedFeedMapper;

    public BreedFeedServiceImpl(BreedFeedMapper breedFeedMapper) {
        this.breedFeedMapper = breedFeedMapper;
    }

    @Override
    public Integer getCount(HashMap<String, Object> map) {
        return breedFeedMapper.getCount(map);
    }

    @Override
    public List<YxProBreedFeed> getListByPage(HashMap<String, Object> map) {
        return breedFeedMapper.getListByPage(map);
    }

    @Override
    public int addBreedFeed(HashMap<String, Object> map) {
        map.put("addTime", getDate());
        return breedFeedMapper.insertSelective(map);
    }

    @Override
    public int updateBreedFeed(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return breedFeedMapper.updateByPrimaryKeySelective(map);
    }

    @Override
    public int deleteBreedFeed(HashMap<String, Object> map) {
        map.put("updateTime", getDate());
        return breedFeedMapper.deleteByPrimaryKey(map);
    }

    @Override
    public List<YxProBreedFeed> getObjByArgs(YxProBreedFeed breedFeed) {
        return breedFeedMapper.getObjByArgs(breedFeed);
    }

    @Override
    public List<YxProBreedFeed> getSearchListByPage(HashMap<String, String> map) {
        return breedFeedMapper.getSearchListByPage(map);
    }

    private String getDate() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(new Date());
    }
}
